<template>
  <div>
    <div>
      <el-table
          ref="multipleTable"
          :data="tableData"
          tooltip-effect="dark"
          style="width: 100%">
        <el-table-column prop="id" label="编号" width="120"></el-table-column>
        <el-table-column prop="purchaseNumber" label="采购单号"></el-table-column>
        <el-table-column prop="suppliersName" label="供应商名称" ></el-table-column>
        <el-table-column prop="status" label="状态" >
          <template #default="scope">
            <div v-if="scope.row.status === 0">
              <span style="margin-left: 10px">{{ "待审核" }}</span>
            </div>
            <div v-if="scope.row.status === 1">
              <span style="margin-left: 10px">{{ "采购完毕" }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" ></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="danger"
              @click="updatePurchase(scope.row)">审核</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="PurchaseDto.pageNum"
          :page-sizes="[3, 6, 9, 12]"
          :page-size="PurchaseDto.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="PurchaseDto.total">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { purchaseList,updatePurchaseStatus } from "@/api/platform/procureAudits";

export default {
  name: "Purchase",
  dicts: ['sys_yes_no'],
  data() {
    return {
      tableData:[],
      PurchaseDto:{
        pageNum:1,
        pageSize:3,
        total:0
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询审核列表 */
    getList() {
      this.loading = true;
      purchaseList(this.PurchaseDto).then(response => {
        console.log(response)
        this.tableData = response.data.rows;
        this.PurchaseDto.total = response.data.total
        });
    },
    updatePurchase(row){
      const id = row.id || this.ids;
      console.log(id)
      updatePurchaseStatus(id).then(response =>{
        console.log(response)
        if (response.code == 200){
          this.$modal.msgSuccess("审核成功");
          this.getList()
        }

      })
    },

    handleSizeChange(val){
      this.PurchaseDto.pageSize = val
      this.getList()
    },

    handleCurrentChange(val){
      this.PurchaseDto.pageNum = val
      this.getList()
    }
  }
};
</script>
